"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var vuex_1 = require("vuex");
var invariant_1 = require("invariant");
exports.getMapState = function (state, nameSpaced) {
    var res = {};
    if (typeof state === 'object') {
        var stateKey_1 = [];
        if (state instanceof Array) {
            stateKey_1 = state;
        }
        else {
            Object.keys(state).map(function (key) {
                stateKey_1.push(key);
            });
        }
        stateKey_1.map(function (key) {
            res[key] = function (state) {
                invariant_1.default(state[nameSpaced], "computed: " + key + ", method: getMapState,error:store can not be null or undefined");
                return state[nameSpaced][key];
            };
        });
    }
    return getState(res);
};
function getState(res) {
    var states = __assign({}, vuex_1.mapState(res));
    return states;
}
exports.getMapPlainState = function (state, nameSpaced) {
    var res = {};
    Object.keys(state).forEach(function (key) {
        res[key] = function (state) {
            var newState = state[nameSpaced][key];
            if (newState.isResolved && newState.data) {
                return newState.data.data;
            }
            return null;
        };
    });
    return getState(res);
};
function getMapAction(type, nameSpaced) {
    if (type && type.constructor === Array) {
        var newAction_1 = {};
        type.map(function (item) {
            newAction_1["" + item] = item;
        });
        var action = __assign({}, vuex_1.mapActions(newAction_1));
        return action;
    }
    return {};
}
exports.getMapAction = getMapAction;
